#ifndef _H_I_SERVICE_H_
#define _H_I_SERVICE_H_

#include "../typedefine.h"
#include "ServiceDelegate.h"
#include "../CMPSCQueueDefine.h"

namespace QWER
{
	QCLASS IServiceFrontend;
	QCLASS IServiceBackend;
	QCLASS CServiceFrontendHelper;
	QCLASS CServiceBackendHelper;
	QCLASS CApplicationHelper;
	QTEMPLATE<typename T> QCLASS CNewBackendMsg;
	QCLASS IServiceMsg;

	QDLL_EXPORT QCLASS IService QABSTRACT
	{
		NON_COPYABLE(IService)
	public:
		IService(CMPSCQueue<IServiceMsg*>& roPipe) :
			m_poPipe(&roPipe)
		{
		}
#ifndef _USING_CLI
		virtual ~IService();
#endif

	protected:
		PTR(IServiceFrontend) _Connect(PTR_OR_REF(CServiceFrontendHelper) roHelper, CONST_PTR_OR_REF(DNewServiceFrontend<IServiceFrontend>) cbNewFrontend);
		PTR(IServiceFrontend) _Connect(PTR_OR_REF(CServiceBackendHelper) roHelper, CONST_PTR_OR_REF(DNewServiceFrontend<IServiceFrontend>) cbNewFrontend);
		PTR(IServiceFrontend) _Connect(PTR_OR_REF(CApplicationHelper) roHelper, CONST_PTR_OR_REF(DNewServiceFrontend<IServiceFrontend>) cbNewFrontend);

	protected:
		PTR(IServiceBackend) m_poBackend = NULL_PTR;

#ifdef _USING_CLI
	internal:
#else
	protected:
		template<typename T> friend class CNewBackendMsg;
		friend class IToServiceBackendMsg;
		friend class CServiceFrontendHelper;
#endif
		void _SetBackend(QMOVEABLE(IServiceBackend) poBackend);
		CMPSCQueue<IServiceMsg*>* m_poPipe = NULL_PTR;
	};
}

#endif
